/**
 * 工具模块
 */
function jsonTransfer(obj) {
  //不是JSONObject的时候，终止递归
  if (typeof obj !== "object" || obj === null) {
    return obj;
  }

  //JSONArray进行迭代
  if (Array.isArray(obj)) {
    return obj.map(jsonTransfer);
  }

  //JSONObject递归访问
  return Object.keys(obj).reduce((result, key) => {
    const camelCaseKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
    result[camelCaseKey] = jsonTransfer(obj[key]);
    return result;
  }, {});
}

function getTime(time) {
  const isoString = time;
  const date = new Date(isoString);

  const year = date.getFullYear();
  const month = (date.getMonth() + 1).toString().padStart(2, "0"); // 补零
  const day = date.getDate().toString().padStart(2, "0");
  const hours = date.getHours().toString().padStart(2, "0");
  const minutes = date.getMinutes().toString().padStart(2, "0");
  const seconds = date.getSeconds().toString().padStart(2, "0");

  const normalTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  console.log(normalTime); // 输出：2025-06-05 21:12:37
  return normalTime;
}

export default {
  jsonTransfer,
  getTime
};
